/**
 * @author hewei
 * @version 1.0
 * @description: 1038. 从二叉搜索树到更大和树
 * @date 2022/10/20 20:33
 */

public class BstToGst {

    int sum = 0;
    public TreeNode bstToGst(TreeNode root) {
        process(root);
        return root;
    }

    public void process(TreeNode node) {
        if (node == null) return;
        process(node.right);
        sum += node.val;
        node.val = sum;
        process(node.left);
    }
}
